Developer.com Click here to support our advertisers
Click here to support our advertisers
SOFTWARE FOR SALE
BOOKS FOR SALE
SEARCH CENTRAL
*JOB BANK
*CLASSIFIEDS
*DIRECTORIES
*REFERENCE
Online Library
*LEARNING CENTER
*JOURNAL
*NEWS CENTRAL
*DOWNLOADS
*COMMUNITY
*CALENDAR
*ABOUT US
-----
Journal:

Get the weekly email highlights from the most popular journal for developers!
Current issue -----
developer.com
developerdirect.com
htmlgoodies.com
javagoodies.com
jars.com
intranetjournal.com
javascripts.com

REFERENCE

All Categories : C/C++

vclp02.htm



- Project 2 -
Analyzing Visual C++ Programs


In this lesson, you learned about the fundamental format of all C++ programs. You saw the following:

  • Visual C++ programs contain a main() function.

  • Braces determine where the main() function begins and ends.

  • Preprocessor directives direct the way Visual C++ compiles your program. Preprocessor directives always begin with a pound sign, #. The #include directive includes files needed by library functions.

  • Visual C++ comments begin with // and end at the end of the line. Comments are for people, not for Visual C++.

  • The cout command outputs data to your screen.

  • All characters are important in Visual C++ programs.

Project 2 Listing. Introduction to Visual C++ programs.


1:  // Filename: PROJECT2.CPP

2:  // Introduces the format of Visual C++ programs and demonstrates

3:  // how to write Visual C++ comments, the #include preprocessor

4:  // directive, and the cout command that outputs data to the

5:  // screen.

6:

7:  #include <iostream.h>

8:

9:  void main()

10:  {

11:    cout << "I have a ";

12:    cout << "Sleekster";       // Continues the output line

13:    cout << " automobile.";    

14:    cout << endl << endl;      // Prints 2 blank lines

15:

16:    cout << "I want to sell my car for $4800 (cheap!)." << endl;

17:    cout << "I have had the car for " << 5 << " years." << endl;

18:    cout << "It's really a grade-" << 'A' << " deal!"

19:         << endl << endl;

20:

21:    return;  // End the program

22:  }

Description

1: A Visual C++ comment that includes the program's filename.

2: A comment that begins the introduction of the program's description.

3: The program's description continues.

4: The program's description continues.

5: The program's description continues.

6: Extra blanks make your program more readable.

7: The cout command needs information in the IOSTREAM.H header file.

8: Extra blanks make your program more readable.

9: All functions have names and the first function in all Visual C++ programs is main().

10: All functions begin with a left brace.

11: The screen output begins.

12: The car's model name prints. No new line occurs.

13: Finish the output.

14: Move the cursor down two lines.

15: Extra blanks make your program more readable.

16: Another message prints.

17: cout prints all kinds of data. Strings and an integer output here.

18: This cout outputs strings and a character literal.

19: Statements can be more than one line.

20: Extra blanks make your program more readable.

21: The final return; in main() always returns control back to Visual C++'s QuickWin window

22: A closing brace always terminates the main() function.



7: The compiler inserts a helpful file here.

10: void means that main() does not return a value to the operating system.

14: endl sends a new line command to the screen.


Output

      
      I have a Sleekster automobile.
      
      I want to sell my car for $4800 (cheap!).
      
      I have had the car for 5 years.
      
      It's really a grade-A deal!

Ruler image
Contact reference@earthweb.com with questions or comments.
Copyright 1998 EarthWeb Inc., All rights reserved.
PLEASE READ THE ACCEPTABLE USAGE STATEMENT.
Copyright 1998 Macmillan Computer Publishing. All rights reserved.
Click here for more info

Click here for more info